<?
/************************************************************************/
/*                       DinCMS: A fresh new CMS                        */
/*                        File:  sql.class.php                          */
/* =====================================================================*/
/*                                                                      */
/* Copyright (c) 2008 by DinCMS Crew                                    */
/* http://dincms.org/                                                   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License.       */
/*                                                                      */
/************************************************************************/

class sql {
		private function remove_html($data)
		{
				$data = htmlentities(strip_tags(stripslashes($data)));
				
				return $data;
		}
		
		public function query($query)
        {	  
              	$query = $this->remove_html($query);
				
              	return mysql_query($query) or die("MySQL Error "$this->errno().". ".$this->error());
        }
        
		public function affected_rows()
		{
              	return mysql_affected_rows() or die("MySQL Error "$this->errno().". ".$this->error());
		}
		
		public function errno($query)
		{				 
              	return mysql_errno();
		}
		
		public function error($query)
		{
              	return mysql_error();
		}
		
		public function fetch_array($query)
		{
				if (!stristr($query, "$sql->query")) {
					die("Wrong use of $sql->fetch_array()! Please see the DinCMS wiki for more information!");
				}
				$query = $this->remove_html($query);
				 
              	return mysql_fetch_array($query) or die("MySQL Error "$this->errno().". ".$this->error());
		}
		
		public function fetch_assoc($query)
		{
				if (!stristr($query, "$sql->query")) {
					die("Wrong use of $sql->fetch_assoc()! Please see the DinCMS wiki for more information!");
				}
				$query = $this->remove_html($query);
				 
              	return mysql_fetch_assoc($query) or die("MySQL Error "$this->errno().". ".$this->error());
		}
		
		public function fetch_row($query)
		{
				if (!stristr($query, "$sql->query")) {
					die("Wrong use of $sql->fetch_row()! Please see the DinCMS wiki for more information!");
				}
				$query = $this->remove_html($query);
				 
              	return mysql_fetch_row($query) or die("MySQL Error "$this->errno().". ".$this->error());
		}
		
		public function insert_id($query)
		{
              	return mysql_insert_id();
		}
		
		public function num_fields($query)
		{
				if (!stristr($query, "$sql->query")) {
					die("Wrong use of $sql->num_fields()! Please see the DinCMS wiki for more information!");
				}
				$query = $this->remove_html($query);
				 
              	return mysql_num_fields($query) or die("MySQL Error "$this->errno().". ".$this->error());
		}
		
		public function num_rows($query)
		{
				if (!stristr($query, "$sql->query")) {
					die("Wrong use of $sql->num_rows()! Please see the DinCMS wiki for more information!");
				}
				$query = $this->remove_html($query);
				 
              	return mysql_num_rows($query) or die("MySQL Error "$this->errno().". ".$this->error());
		}
		
		public function result($query)
		{
				if (!stristr($query, "$sql->query")) {
					die("Wrong use of $sql->result()! Please see the DinCMS wiki for more information!");
				}
				$query = $this->remove_html($query);
				 
              	return mysql_result($query,0) or die("MySQL Error "$this->errno().". ".$this->error());
		}
		
}
?>